/**
 * Created by sunyx on 2016/9/29.
 */
import React, { PropTypes } from 'react';
import FormModal from '../../components/FormModal';
import {Form, Input} from 'antd';
import {post} from '../../logics/rpc';
import md5 from "../../logics/md5";
import alert from '../../utils/alert';

@Form.create()
export default class AddGoodModal extends React.Component {
  onReturn = ev => {
    this.refs.form.submit();
  };
  fields = {
    title:  {
      rules: [
        { required: true, message: '礼包名' },
      ],
    },
    content: {
      rules: [
        { required: true, message: '礼包内容' },
      ],
    },
    total: {
      rules: [
        { required: true, message: '礼包总数' },
      ],
    },
    remain: {
      rules: [
        { required: true, message: '礼包剩余数' },
      ],
    },
    func: {
      rules: [
        { required: true, message: '礼包使用范围' },
      ],
    },
    scope: {
      rules: [
        { required: true, message: '礼包使用范围' },
      ],
    },
    names: {
      rules: [
        { required: true, message: '礼包码' },
      ],
    },
  };
  submit = async ({title,content,total,remain,func,names,scope}) => {
    await post('/admin/game/addPackage', {
    title,content,total,remain,func,names,scope
    });
    alert('创建成功');
    const {onAdded} = this.props;
    onAdded && onAdded();
  };
  render() {
    const { fields } = this;
    const { getFieldProps } = this.props.form;
    return (
      <FormModal
        ref="form"
        title="添加礼包"
        okTitle="确 定"
        onSubmit={this.submit}
        {...this.props}
      >
        <Form.Item label="礼包名">
          <Input {...getFieldProps('title', fields.title)} onPressEnter={this.onReturn} />
        </Form.Item>
        <Form.Item label="礼包内容">
          <Input {...getFieldProps('content', fields.content)} onPressEnter={this.onReturn} />
        </Form.Item>
        <Form.Item label="礼包总数">
          <Input {...getFieldProps('total', fields.total)} onPressEnter={this.onReturn} />
        </Form.Item>
        <Form.Item label="剩余数量">
          <Input {...getFieldProps('remain', fields.remain)} onPressEnter={this.onReturn} />
        </Form.Item>
        <Form.Item label="礼包使用范围">
        <Input {...getFieldProps('func', fields.func)} onPressEnter={this.onReturn} />
      </Form.Item>
        <Form.Item label="礼包使用方法">
          <Input {...getFieldProps('scope', fields.scope)} onPressEnter={this.onReturn} />
        </Form.Item>
        <Form.Item label="礼包码">
          <Input {...getFieldProps('names', fields.names)} onPressEnter={this.onReturn} />
        </Form.Item>
      </FormModal>
    );
  }
}
